Skip to content

Add dynamic key allocation support for Dilithium#10180

Merged
dgarske merged 2 commits intowolfSSL:masterfrom
Frauschi:dilithium-alloc-key
Apr 15, 2026
Merged

Add dynamic key allocation support for Dilithium#10180
dgarske merged 2 commits intowolfSSL:masterfrom
Frauschi:dilithium-alloc-key

Conversation

@Frauschi
Copy link
Copy Markdown
Contributor

@Frauschi Frauschi commented Apr 9, 2026

This update introduces the WOLFSSL_DILITHIUM_DYNAMIC_KEYS option, allowing for dynamic memory allocation of public and private key buffers in dilithium_key objects. This change reduces memory usage by allocating buffers only when needed.

This greatly reduces dynamic memory usage during peer verification when using ML-DSA certificates, which is especially important for resource-constrained systems.

@Frauschi Frauschi self-assigned this Apr 9, 2026
@Frauschi Frauschi force-pushed the dilithium-alloc-key branch from 293ca19 to ca52a56 Compare April 10, 2026 15:10
@Frauschi
Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Apr 10, 2026
@Frauschi Frauschi requested review from SparkiDev and dgarske and removed request for dgarske April 10, 2026 19:01
Copy link
Copy Markdown
Contributor

@dgarske dgarske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🐺 Skoll Code Review

Overall recommendation: REQUEST_CHANGES
Findings: 4 total — 3 posted, 1 skipped

Posted findings

  • [High] Heap buffer overflow in wc_dilithium_set_level ForceZero when FIPS204_DRAFT is enabledwolfcrypt/src/dilithium.c:11017-11021
  • [Medium] oqs_dilithium_make_key missing USE_INTEL_SPEEDUP +8 alignment paddingwolfcrypt/src/dilithium.c:10077-10093
  • [Low] Return value of wc_dilithium_size/wc_dilithium_pub_size not validated before use as allocation sizewolfcrypt/src/dilithium.c:7673
Skipped findings
  • [Medium] Duplicated dynamic key allocation pattern across 5 call sites

Review generated by Skoll via openclaw

Comment thread wolfcrypt/src/dilithium.c
Comment thread wolfcrypt/src/dilithium.c
Comment thread wolfcrypt/src/dilithium.c Outdated
@dgarske dgarske assigned Frauschi and unassigned wolfSSL-Bot Apr 10, 2026
@Frauschi Frauschi force-pushed the dilithium-alloc-key branch 2 times, most recently from 207c324 to 74c9ca3 Compare April 11, 2026 08:56
@Frauschi
Copy link
Copy Markdown
Contributor Author

@dgarske fixed all review comments and did some more code cleanup.

@Frauschi Frauschi requested a review from dgarske April 11, 2026 09:21
@Frauschi Frauschi assigned wolfSSL-Bot and unassigned Frauschi Apr 11, 2026
SparkiDev
SparkiDev previously approved these changes Apr 13, 2026
Copy link
Copy Markdown

@wolfSSL-Fenrir-bot wolfSSL-Fenrir-bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fenrir Automated Review — PR #10180

Scan targets checked: wolfcrypt-api_misuse, wolfcrypt-bugs, wolfcrypt-compliance, wolfcrypt-concurrency, wolfcrypt-consttime, wolfcrypt-defaults, wolfcrypt-mutation, wolfcrypt-portability, wolfcrypt-proptest, wolfcrypt-src, wolfcrypt-zeroize

Findings: 3
3 finding(s) posted as inline comments (see file-level comments below)

This review was generated automatically by Fenrir. Findings are non-blocking.

Comment thread wolfcrypt/src/wc_pkcs11.c
Comment thread wolfcrypt/src/dilithium.c
Comment thread wolfcrypt/src/dilithium.c
@Frauschi
Copy link
Copy Markdown
Contributor Author

Fixed the identified issues by actually storing the sizes of the allocated buffers in the key object now. This gets rid of all the potentially erroneous calls to the _size() methods.

Furthermore, I added a second commit to fix zd21610 by making the w1e buffer in the dilithium_sign_with_seed_mu() method aware of SMALL_STACK in WOLFSSL_DILITHIUM_SIGN_SMALL_MEM builds.

@Frauschi Frauschi requested a review from SparkiDev April 13, 2026 17:29
Comment thread wolfssl/wolfcrypt/dilithium.h Outdated
This update introduces the WOLFSSL_DILITHIUM_DYNAMIC_KEYS option, allowing
for dynamic memory allocation of public and private key buffers. This change
reduces memory usage by allocating buffers only when needed.
@Frauschi Frauschi force-pushed the dilithium-alloc-key branch from 2b6181c to 064cfe2 Compare April 14, 2026 11:22
@Frauschi Frauschi removed their assignment Apr 14, 2026
@Frauschi Frauschi requested a review from SparkiDev April 14, 2026 11:23
@Frauschi
Copy link
Copy Markdown
Contributor Author

Jenkins retest this please

@SparkiDev
Copy link
Copy Markdown
Contributor

SparkiDev commented Apr 14, 2026

retest this please

Windows: tcp bind failed

@dgarske dgarske merged commit 48a0347 into wolfSSL:master Apr 15, 2026
426 of 433 checks passed
@Frauschi Frauschi deleted the dilithium-alloc-key branch April 15, 2026 18:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants